<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <a href="#/news">新闻</a>
        <a href="#/home">主页</a>

        <fieldset>
            <legend>页面</legend>
            <h1 id="hh"></h1>
        </fieldset>
    </div>
</body>

</html>
<script>
    //hash模式 是依靠监听hash的改变来实现页面效果的切换

    //监听hash改变的方法叫做onhashchange 当hash值没有发生变化的时候 是不会触发hashchange的回调的

    //通过location.hash来获取

    //hash模式不会向浏览器发起请求

    window.onhashchange = function () {
        let hash = location.hash;
        console.log(hash);
        switch (hash) {
            case "#/news":
                hh.innerHTML = "今日头条,新闻页"
                break;
            case "#/home":
                hh.innerHTML = "个人中心"

        }
    }
</script>